package com.stein.mentalarithmetic;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.Constructor;
import com.badlogic.gdx.utils.reflect.ReflectionException;

public class Mentalarithmetic extends ApplicationAdapter {
	BaseTest[] listEntries  ;

	SpriteBatch batch;
	Texture img;
	Skin skin;
	Stage stage;
	Label fpsLabel;
	  Window testWindow ;
	@Override
	public void create () {
		skin = new Skin(Gdx.files.internal("data/uiskin.json"));
		stage = new Stage();
		Gdx.input.setInputProcessor(stage);
		
		testWindow = new Window("Test", skin);
		testWindow.setPosition(300, 0);
		testWindow.setWidth(300);
		stage.addActor(testWindow);
		BaseTest[] listEntries ={
				new Test23X11(skin),
				new TestX5Square(skin),
				new Test62X68(skin),
				new Test2030_1_1(skin),
				new Test23Add33(skin),
				new Test234Add334(skin),
				new Test234Add334_2(skin),
				new TestxAddy_4(skin),
				
				} ;
		this.listEntries=listEntries;
		final List<BaseTest> list = new List<BaseTest>(skin);
		list.setItems(listEntries);
		list.getSelection().setMultiple(true);
		list.getSelection().setRequired(false);
		// list.getSelection().setToggle(true);
		ScrollPane scrollPane2 = new ScrollPane(list, skin);
		scrollPane2.setFlickScroll(false);
		fpsLabel = new Label("fps:", skin);
		
		  Window window = new Window("Dialog", skin);
		  
		window.setPosition(0, 0);
		window.defaults().spaceBottom(10);
		window.row();
		window.add(scrollPane2).fill().expand().colspan(4).maxHeight(200);
		window.row();
		window.add(fpsLabel).colspan(4);
		window.pack();
		window.setWidth(200);
		stage.addActor(window);
		//batch = new SpriteBatch();
		//img = new Texture("badlogic.jpg");
		list.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				BaseTest bt = list.getSelected();
				if(bt!=null)
				 bt.init(testWindow);
					//new Test23X11(skin).init(testWindow);;
				super.clicked(event, x, y);
			}
		});
	}

	@Override
	public void render () {
		/*Gdx.gl.glClearColor(1, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		batch.begin();
		batch.draw(img, 0, 0);
		batch.end();*/
		Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		fpsLabel.setText("fps: " + Gdx.graphics.getFramesPerSecond());

		stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));
		stage.draw();
	}
	@Override
	public void resize (int width, int height) {
		stage.getViewport().update(width, height, true);
	}
	@Override
	public void dispose () {
		stage.dispose();
		skin.dispose();
		}
}
